﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.IO;
using SharpVectors.Runtime;
using SharpVectors.Renderers;
using SharpVectors.Renderers.Wpf;
using SharpVectors.Converters;
using Microsoft.Win32;

namespace RoundupReadyPlusWPF.Pages
{
    /// <summary>
    /// Interaction logic for PageState.xaml
    /// </summary>
    public partial class PageState : UserControl
    {

        public PageState()
        {
            InitializeComponent();

            SvgDrawingCanvas canvas = (SvgDrawingCanvas)mapa.DrawingCanvas;

            canvas.MouseMove += new MouseEventHandler(canvas_MouseMove);

        }

        private void canvas_MouseMove(object sender, MouseEventArgs e)
        {
            

           // Drawing hitVisual = HitTest(pt);
        }

        private void mapa_MouseUp(object sender, MouseButtonEventArgs e)
        {
            SvgDrawingCanvas canvas = (SvgDrawingCanvas)mapa.DrawingCanvas;

            Point pt = e.GetPosition(canvas);

            // Por algum motivo ainda desconhecido o click no mapa esta
            // com um shift, e por esse motivo e necessário inserir dados 
            // de calibracao da area de click do mapa na tela
            pt.X = pt.X + 6250;
            pt.Y = pt.Y + 890;

            List<Drawing> drawObjects = canvas.DrawObjects;

            foreach (GeometryDrawing drawing in drawObjects)
            {
                string id = drawing.GetValue(FrameworkElement.NameProperty) as string;              

                if (drawing.Geometry.FillContains(pt))
                {
                    lblState.Content =  id;
                    SolidColorBrush brush = new SolidColorBrush(Color.FromArgb(0xff, 0x92, 0x02, 0x26));

                    if (drawing.Brush == null)
                    {
                        drawing.Brush = brush;
                    }
                    else
                    {
                        drawing.Brush = null;
                    }
                }

            }
            
        }


    }
}
